Crate hex_simd

source ·
Expand description

SIMD-accelerated hex encoding and decoding.

Examples

use hex_simd::AsciiCase;

let bytes = b"Hello world!";

let encoded = hex_simd::encode_to_string(bytes, AsciiCase::Lower);
assert_eq!(encoded, "48656c6c6f20776f726c6421");

let decoded = hex_simd::decode_to_vec(encoded).unwrap();
assert_eq!(decoded, bytes);

Profile settings

To ensure maximum performance, the following profile settings are recommended when compiling this crate:

opt-level = 3
lto = "fat"
codegen-units = 1

CPU feature detection

The feature flag detect is enabled by default.

When the feature flag detect is enabled, the APIs will test at runtime whether the CPU (and OS) supports the required instruction set. The runtime detection will be skipped if the fastest implementation is already available at compile-time.

When the feature flag detect is disabled, the APIs will test at compile-time whether the compiler flags supports the required instruction set.

If the environment supports SIMD acceleration, the APIs will call SIMD functions under the hood. Otherwise, the APIs will call fallback functions.

When the feature flag unstable is enabled, this crate requires the nightly toolchain to compile.

no_std support

You can disable the default features to use this crate in a no_std environment.

You can enable the feature flag alloc if the environment supports heap allocation.

Currently the feature flag detect depends on the standard library. Dynamic CPU feature detection is not available in no_std environments.

Structs

Hex Error
Out reference (&'a out T).

Enums

An enum type which represents the case of ascii letters.

Traits

Types that can append bytes decoded from a hex string.
Types that can append a hex string.
Extension trait for converting a mutable reference to an out reference.
Types that can be decoded from a hex string.
Types that can represent a hex string.

Functions

Checks whether data is a hex string.
Decodes a hex string to bytes case-insensitively.
Decodes a hex string to bytes case-insensitively and appends to a specified type.
Decodes a hex string to bytes case-insensitively and writes inplace.
Decodes a hex string to bytes case-insensitively.
Decodes a hex string to bytes case-insensitively and returns a specified type.
Calculates the decoded length.
Encodes bytes to a hex string.
Encodes bytes to a hex string and appends to a specified type.
Encodes bytes to a hex string and returns &mut str.
Encodes bytes to a hex string.
Encodes bytes to a hex string and returns a specified type.
Calculates the encoded length.